<!DOCTYPE html>
<html lang="en">

<head>
  <meta charset="UTF-8">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <meta http-equiv="X-UA-Compatible" content="ie=edge">
  <title>Document</title>
  <style>
    * {
      margin: 0;
      padding: 0;
    }

    body {
      height: 2000px;
      background: linear-gradient(green, yellow, pink);
    }

    #box {
      width: 100%;
      height: 500px;
      background: orchid;
    }

    ul {
      list-style: none;
      width: 100%;
      height: 80px;
      background: darkorange;
      display: flex;
    }

    .fixed {
      position: fixed;
      top: 0;
      left: 0;
    }

    #goTop {
      width: 200px;
      height: 80px;
      background: skyblue;
      position: fixed;
      bottom: 90px;
      right: 20px;
      display: none;
    }
  </style>
</head>

<body>
  <div id="box"></div>
  <ul>
    <li>首页</li>
    <li>新闻</li>
    <li>股市</li>
  </ul>
  <button id="goTop">回到顶部</button>
  <script src="jquery-3.4.1.min.js"></script>
  <script>
    var ulOffetTop = $("ul").offset().top;
    console.log(ulOffetTop)
    $(window).scroll(function () {
      // 获取页面的滚动距离
      var top = $(window).scrollTop();
      if (top > ulOffetTop) {
        $("ul").addClass("fixed")
        $("#goTop").show()
      } else {
        $("ul").removeClass("fixed")
        $("#goTop").hide()
      }

    })
    // 回到顶部
    $("#goTop").click(function () {
      $("body,html").animate({ scrollTop: 0 }, 1000)
    })


  </script>
</body>

</html>